<include file='Index/header' />
<div class="row">
	<br>

	<div class="col-sm-12">
		<div class="col-sm-2"></div>

		<div class="col-sm-2" style="padding-top:5px;">
			<label for="key" class="control-label" >关键字：</label>
		</div>
		<div class="col-sm-4">
			<input id="key" name="key" class="form-control"></input>
		</div>
  </div>
	
	<form id="product_discount_add_form" action='{:U("Admin/Product/updateProductDiscount")}' method="post">
		<div class="col-sm-12">
			<br>
			<div class="col-sm-2">
				<table>
				<tr>请选择仓库：</tr>
				<tr><ul id="repositoryTree" class="ztree"></ul></tr>
				<br>
				<tr>请选择商品类别：</tr>
				<tr><ul id="product_class_option_tree" class="ztree"></ul></tr>
				</table>
			</div>
			<div class="col-sm-10">
				<table id="product-table" class="table table-hover table-bordered table-striped table-striped">
					<thead>
						<tr>
							<td>大类</td>
							<td>中类</td>
							<td>子类</td>
							<td>关键字</td>
							<td>货号</td>
							<td>a仓库</td>
							<td>b仓库</td>
							<td>选择</td>
							<td>编号</td>
							<td>商品名称</td>
							<td>条形码货号</td>
							<td>价格</td>
							<td>上架</td>
							<td>库存</td>
							<td>排序</td>
						</tr>
					</thead>
					<tbody>

					</tbody>
				</table>
			</div>
		</div>

		<div class="col-sm-12">
			<br>
			<div class="col-sm-2"></div>
			<div class="col-sm-2">
				<label for="cx_price" class="form-label" style="padding-top:5px;">促销价格</label>
			</div>
			<div class="col-sm-4">
				<input id="cx_price" name="cx_price" class="form-control"></input>
			</div>
		</div>

		<div class="col-sm-12">
			<br>
			<div class="col-sm-2"></div>
			<div class="col-sm-2">
				<label for="cx_amount" class="form-label" style="padding-top:5px;">促销量</label>
			</div>
			<div class="col-sm-4">
				<input id="cx_amount" name="cx_amount" class="form-control"></input>
			</div>
		</div>

		<div class="col-sm-12">
			<br>
			<div class="col-sm-2"></div>
			<div class="col-sm-2">
				<label for="xg_amount" class="form-label" style="padding-top:5px;">限购量</label>
			</div>
			<div class="col-sm-4">
				<input id="xg_amount" name="xg_amount" class="form-control"></input>
			</div>
		</div>

		<div class="col-sm-12">
			<br>
			<div class="col-sm-2"></div>
			<div class="col-sm-2">
				<label for="index" class="form-label" style="padding-top:5px;">排序</label>
			</div>
			<div class="col-sm-4">
				<input id="index" name="index" class="form-control"></input>
			</div>
		</div>

	</form>

	<div class="col-sm-12">
			<br><br>
			<div class="col-sm-2"></div>
			<div class="col-sm-2"></div>
			<div class="col-sm-2">
    		<button class="btn btn-primary" onclick="submit()">保存</button>
    	</div>
    	<div class="col-sm-3">
    		<button class="btn btn-primary">取消</button>
    	</div>
    	<br><br>
	  </div>

</div>

<include file='Index/footer' />
<include file='Product/product-detail' />
<script>
$(document).ready(function() {
	loadRepositoryTree('repositoryTree', true);
	loadProductClassTree('product_class_option_tree', true, false);
	loadTable();		
});
var table;
function loadTable(){
	table = $('#product-table').DataTable({
		"bProcessing": true,
		"bDestroy": true,
		"sPaginationType" : "input",
		"oLanguage" : {
              "sLengthMenu": "每页显示 _MENU_ 条记录",
              "sZeroRecords": "抱歉， 没有找到",
              "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
              "sInfoEmpty": "没有数据",
              "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
              "sZeroRecords": "没有检索到数据",
               "sSearch": "搜索: &nbsp",
              "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
              }
          }, 
		"ajax":'{:U("Admin/Product/getProduct/")}',
		"columns": [
					{ "data":'product_template'},
					{ "data":'product_template'},
					{ "data":'product_template'},
					{ "data":'product_template'},
					{ "data":'product_template'},
					{ "data":'a_repository_id'},
					{ "data":'b_repository_id'},
					{ "data": 'product_id' },
	        { "data": 'id' },
	        { "data": 'name' },
	        { "data": 'product_template' },
	        { "data": 'kj_price' },
	        { "data": 'status' },
	        { "data": 'default_amount' },
	        { "data": 'index' }
    ],
    "columnDefs": [
	    {
	    	"targets": [0, 1, 2, 3, 4, 5, 6],
	      "visible":false
	    },
	    {
	    	"targets": 0,
	    	"render": function (data, type, row, table) {
	    		return data.class1;
	      }
	    },
	    {
	    	"targets": 1,
	    	"render": function (data, type, row, table) {
	    		return data.class2;
	      }
	    },
	    {
	    	"targets": 2,
	    	"render": function (data, type, row, table) {
	    		return data.class3;
	      }
	    },
	    {
	    	"targets": 3,
	    	"render": function (data, type, row, table) {
	    		return data.key;
	      }
	    },
	    {
	    	"targets": 7,
	    	"render": function (data, type, row, table) {
	    		return '<input type="checkbox" name="product_ids[]" value="'+data+'" />';
	      }
	    },
	    {
	    	"targets": 8,
	    	"render": function (data, type, row, table) {
	    		return table.row + 1;
	      }
	    },
	    {
	    	"targets": 10,

	    	"render": function (data, type, row, table) {
	    		return data.barcode;
	      }
	    },
	    {
	    	"targets": 12,
	    	"render": function (data, type, row, table) {
	    		return data == '0'? "是":"否";
	      }
	    },
    ]
	});
	
	$("#key").keyup(function(){
		table.column(3).search(this.value).draw();
  });
}

function searchARepository(val){
	table.column(5).search('').draw();
	table.column(6).search('').draw();
	table.column(5).search(val).draw();
}

function searchBRepository(val){
	table.column(5).search('').draw();
	table.column(6).search('').draw();
	table.column(6).search(val).draw();
}

function searchClass1(product_class_id){
	table.column(0).search('').draw();
	table.column(1).search('').draw();
	table.column(2).search('').draw();
  table.column(0).search(product_class_id).draw();
}
function searchClass2(product_class_id){
	table.column(0).search('').draw();
	table.column(1).search('').draw();
	table.column(2).search('').draw();
  table.column(1).search(product_class_id).draw();
}
function searchClass3(product_class_id){
	table.column(0).search('').draw();
	table.column(1).search('').draw();
	table.column(2).search('').draw();
  table.column(2).search(product_class_id).draw();
}

function submit(){
	 $('#product_discount_add_form').ajaxSubmit({
        success:function(data){
            window.location.href = '{:U("Admin/Product/productDiscountList")}';
        }
    });
}
</script>
